package com.ztgf.user.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.user.models.service.IUserImService;
import com.ztgf.user.models.bo.UserImBO;
import com.ztgf.user.models.dto.UserImDTO;

/**
 * im账号表控制器
 *
 * @author zhanghualang
 * @Date 2020-05-28 17:48:46
 */

@RestController
@RequestMapping("/api/userIm")
@Slf4j
@Api(value = "UserImApiController",tags = "im账号表Api接口")
public class UserImApiController {

    @DubboReference
    private IUserImService userImService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<UserImDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        UserImDTO dto = userImService.selectById(id);

        return new Result<>(dto);
    }
    @PostMapping("/getSellerByUserId")
    @ApiOperation(value = "根据userId获取卖家IM",notes = "根据userId获取卖家IM")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<UserImDTO> getSellerByUserId(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        UserImDTO dto = userImService.getSellerByUserId(id);

        return new Result<>(dto);
    }


    @ApiOperation(value = "im账号表列表",notes = "im账号表列表")
    @PostMapping("/queryPageList")
    public Result<Page<UserImDTO>> queryPageList(UserImBO bo){
       Wrapper<UserImDTO> wrapper = new EntityWrapper<>();
        Page<UserImDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = userImService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
